{% extends "admin/base.html" %}


{% block content_main %}
    <blockquote class="layui-elem-quote">已持有该题库的老师</blockquote>
    <table id="demo" lay-filter="test"></table>
    <blockquote class="layui-elem-quote">未持有该题库的老师</blockquote>
    <table id="demo2" lay-filter="test2"></table>

    <script type="text/html" id="barDemo">
      <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">从题库中移除</a>
    </script>
    <script type="text/html" id="barDemo2">
      <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">添加到题库中</a>
    </script>
{% endblock %}


{% block script %}
<script>
    var id_question_bank = window.location.href.split("?")[1].split("=")[1];
    layui.use(function() {
        var table = layui.table; //表格
        var dropdown = layui.dropdown; //下拉菜单
        var layer = layui.layer;

        // 执行一个 table 实例
        table.render({
            elem: '#demo'
            , url: '/teacher_question_bank_rel/query_teacher_in_bank?id_question_bank='+id_question_bank //数据接口（此处为静态数据，仅作演示）
            , page: false //开启分页
            , toolbar: true  //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , cols: [[ //表头
                {#{type: 'checkbox', fixed: 'left'}#}
                {field: 'name', title: '老师名字', width: 200}
                , {field: 'phone', title: '电话', width: 200}
                , {fixed: 'right', title: '操作', width: 200, align:'center', toolbar: '#barDemo'}
            ]]
        });
        table.render({
            elem: '#demo2'
            , url: '/teacher_question_bank_rel/query_teacher_not_in_bank?id_question_bank='+id_question_bank //数据接口（此处为静态数据，仅作演示）
            , page: false //开启分页
            , toolbar: true  //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , cols: [[ //表头
                {#{type: 'checkbox', fixed: 'left'}#}
                {field: 'name', title: '老师名字', width: 200}
                , {field: 'phone', title: '电话', width: 200}
                , {fixed: 'right', title: '操作', width: 200, align:'center', toolbar: '#barDemo2'}
            ]]
        });

        // 单元格工具事件
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
            ,layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'detail'){
              {#layer.msg('查看操作');#}
                $.post(
                    "/teacher_question_bank_rel/remove_from_bank",
                    {
                        "id_question_bank": id_question_bank,
                        "id_teacher": data.id
                    },
                    function (data,status) {
                        if(data == "success"){
                            window.location.reload();
                        }
                    }
                );
            }
        });
        table.on('tool(test2)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
            ,layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'detail'){
              {#layer.msg('查看操作');#}
                $.post(
                    "/teacher_question_bank_rel/add_to_bank",
                    {
                        "id_question_bank": id_question_bank,
                        "id_teacher": data.id
                    },
                    function (data,status) {
                        if(data == "success"){
                            window.location.reload();
                        }
                    }
                );
            }
        });
    });
    </script>
{% endblock %}
